import socket
from os import system
from loguru import logger


logger.add('Get\'s_url.log')
PORT = 84

logger.info(f'Start Get Message:\n\ton port:{PORT}')
udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_server.bind(("127.0.0.1", PORT))  # 绑定这个端口，接收端口消息

while True:
    data, addr = udp_server.recvfrom(1024)  # 1024缓冲区
    data = data.decode('utf-8')
    if data == 'quit':
        '''是否为退出指令'''
        logger.warning('接受到来自Sender的quit')
        data, addr = udp_server.recvfrom(1024)  # 1024缓冲区
        if data.upper() == 'ACK':
            logger.info('客户端已确认想关闭服务端，是否关闭')
            a = input()
            if a == 'ack':
                break

    if data[:7] == 'connect':
        pass

    logger.info(data)
    logger.debug(addr)# 将接收的消息发给系统

udp_server.close()
if __name__ == '__main__':
    pass
